import {
  ComponentWithStore
} from "mobx-miniprogram-bindings";
import {
  reqAddOrder
} from '@/api/order'
import { toast } from "@/utils/extendApi";
ComponentWithStore({
  properties: {
    tempOrderStr: String
  },
  data: {
    tempOrder: {},
    showPayType: false,
    payType:'',
    payTypeList: [{
        name: "微信支付",
        code: 1
      },
      {
        name: "银行卡支付",
        code: 2
      }
    ]
  },
  methods: {
    toFeeDetail() {
      wx.navigateTo({
        url: '/pages/fee-detail/fee-detail',
      })
    },
    closeShowPayType() {
      this.setData({
        showPayType: false
      })
    },
    handleShowPayType() {
      this.setData({
        showPayType: true
      })
    },

    selectPayType(event) {
      this.setData({
        'payType': event.detail.code
      })
    },
    async submit() {
      if(!this.data.payType){
        toast({title:"请选择支付方式"})
        return
      }
      this.data.tempOrder.payType=this.data.payType
      this.data.tempOrder.orderStatus = 1
      await reqAddOrder(this.data.tempOrder)
      toast({icon:'success',title:'支付成功'})
      setTimeout(()=>{
        wx.showTabBar()
        wx.switchTab({
          url: '/pages/order/list/list',
        })
      },1000)
    }
  },
  lifetimes: {
    attached() {
      this.setData({
        tempOrder: JSON.parse(this.properties.tempOrderStr)
      })
    }
  }
})